package com.soup.lab.executor.pool2.test;

import com.soup.lab.executor.pool2.Node;
import org.junit.jupiter.api.Test;

import java.util.concurrent.TimeUnit;

public class NodeTestCase {

    private volatile static int i = 1;

    @Test
    public void test1() throws InterruptedException {
        /*Node<Runnable> node = new Node<Runnable>(new PrintRunnable(i++));
        new Thread(node).start();
        new Thread(() -> {
           while (i < 5) {
               node.add(new PrintRunnable(i++));
               try {
                   TimeUnit.SECONDS.sleep(1);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
           System.out.println(node.cancel());
        }).start();
        TimeUnit.MINUTES.sleep(1);*/

    }

    static class PrintRunnable implements Runnable {

        private final Object content;

        public PrintRunnable(Object content) {
            this.content = content;
        }

        @Override
        public void run() {
            System.out.println(content);
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        @Override
        public String toString() {
            return "PrintRunnable{" +
                    "content=" + content +
                    '}';
        }
    }

}
